﻿using MediatR;
using RBAC.Common.Domains.RabbitProject;
using RBAC.Common.Dto;
using RBAC.Common.infrastructures.interfaces;
using RBAC.Enum;

namespace RBAC.api.Application.commond.FarmingInformation
{
    public class FarmingUpdateHander : IRequestHandler<FarmingUpdateCommond, Rulst>
    {

        private readonly IbaseRpository<breedMess> _BreedMess;

        public FarmingUpdateHander(IbaseRpository<breedMess> breedMess)
        {
            _BreedMess = breedMess;
        }

        public async Task<Rulst> Handle(FarmingUpdateCommond request, CancellationToken cancellationToken)
        {
            var query = new Rulst() { Code = (int)Reult.success };
            ///ok这是个修改方法也是个添加的方法
            ///因为我在页面去添加我们的企业的时候会遇到一个问题
            ///就是我们的企业已经有了
            ///但是我们的弹窗还需要去添加这时我么的添加需要时是一个修改
            ///帮助我们去执行修改的方式
            var list=_BreedMess.Query().Where(x=>x.ProDuctionBasicid==request.ProDuctionBasicid).FirstOrDefault();
            if(list!=null)
            {
              
                list.varietyName=request.varietyName;
                list.Breedcome = request.Breedcome;
                list.BreedDay = request.BreedDay;
                list .Fodderbrand=request.Fodderbrand;
                list .FodderName=request.FodderName;
                list .ColumnTime=request.ColumnTime;
                list.ProDuctionBasicid = request.ProDuctionBasicid;
                query.Code = _BreedMess.update(list);
            }
            else
            {
                var gh = new breedMess()
                {
                    varietyName=request.varietyName,
                    Breedcome=request.Breedcome,
                    BreedDay=request.BreedDay,
                    Fodderbrand=request.Fodderbrand,
                    FodderName=request.FodderName,
                    ColumnTime=request.ColumnTime,
                    Farm="",
                    FarmName="",
                    Framnum=0,
                    ProDuctionBasicid=request.ProDuctionBasicid,
                    Vaccineid=0
                };

                _BreedMess.Add(gh);

            }


         


            return query;

        }
    }
}
